package org.jeecg.modules.friends.transfer;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.friends.auth.entity.UserAuthentication;
import org.jeecg.modules.friends.user.dto.AuthInfoDTO;

/**
 * Created on 2024-08-22
 */
public class UserTransfer {
    public static AuthInfoDTO convertToUserAuthenticationDTO(UserAuthentication userAuthentication) {
        AuthInfoDTO userAuthenticationDTO = new AuthInfoDTO();
        userAuthenticationDTO.setAuthStatus(userAuthentication.getAuthStatus());
        userAuthenticationDTO.setAuthType(userAuthentication.getAuthType());
        userAuthenticationDTO.setCompanyName(userAuthentication.getCompanyName());
        userAuthenticationDTO.setEducation(userAuthentication.getEducation());
        userAuthenticationDTO.setEducationType(userAuthentication.getEducationType());
        userAuthenticationDTO.setIdCardNo(encryptIdCardNo(userAuthentication.getIdCardNo()));
        userAuthenticationDTO.setJob(userAuthentication.getJob());
        if (StringUtils.isNotEmpty(userAuthentication.getRealName())) {
            userAuthenticationDTO.setRealName(userAuthentication.getRealName().substring(0, 1) + "**");
        }
        userAuthenticationDTO.setSchoolName(userAuthentication.getUniversity());
        userAuthenticationDTO.setIsStudent(userAuthentication.getIsStudent());
        return userAuthenticationDTO;
    }
    private static  String encryptIdCardNo(String idCardNo) {
        if (StringUtils.isEmpty(idCardNo)) {
            return idCardNo;
        }
        idCardNo = idCardNo.substring(0, 3) + "****";
        return idCardNo;
    }

}
